package Collection;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @author wuhan
 * @date 2019/9/26 14:34
 */
class StringLengthComparator implements Comparator{
    @Override
    public int compare(Object o1, Object o2) {
        String s1=(String) o1;
        String s2=(String) o2;
        int num=new Integer(s1.length()).compareTo(new Integer(s2.length()));
        if (num==0){
            return s1.compareTo(s2);
        }
        return num;
    }
}
public class TreeSetPractice {


    public static void main(String[] args) {
        TreeSet<String> ts=new TreeSet<String>(new StringLengthComparator());
        ts.add("qwqsdfsdfds");
        ts.add("adfsedf");
        ts.add("asfsdfsedefsefc");
        ts.add("asfsdfsedefssdfdsfefc");
        ts.add("adfserf");

        for (Object t : ts) {
            String s=(String) t;
            System.out.println(s);
        }
    }

}
